<template>
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="姓名" prop="name">
            <el-input type="name"  v-model="name"></el-input>
        </el-form-item>
        <el-form-item label="账号" prop="account">
            <el-input type="account"  v-model="account"></el-input>
        </el-form-item>

        <el-form-item label="电话号" prop="phone">
            <el-input type="phone" v-model="phone"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input type="password" v-model="password"></el-input>
        </el-form-item>

        <el-form-item label="角色" prop="role">
            <el-input type="role" v-model="role"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm()">提交</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import qs from 'qs'
import { create } from 'domain'
export default{
    data(){
        return{
            name:'',
            account:'',
            phone:'',
            password:'',
            role:''
        }
    },
    methods: {
        submitForm() {
           const id = this.$route.query.id
        //    console.log(id)
           let params=qs.stringify({
            name:this.name,
            account:this.account,
            phone: this.phone,
            password: this.password,
            role: this.role,
            id:id
           })
           this.axios.post('http://127.0.0.1:9090/user/update',params).then((result)=>{
            this.$router.replace('/user')
            // alert("修改成功")
           }).catch((err)=>{
            alert("修改失败")
           })
        },
        resetForm() {
            this.name='',
            this.account='',
            this.phone='',
            this.password='',
            this.role='' 
        },

        selectById(){
            const id = this.$route.query.id
            this.axios.get('http://127.0.0.1:9090/user/selectOne?id='+id).then((result)=>{
                console.log(result)
            })

        }
    },
    mounted(){
       this.selectById()
    },
    created(){
       this.selectById()
    }
    
    
}
</script>